<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" :form="form">
        <a-row :gutter="24">
          <a-col :md="6">
            <a-form-item label="题名">
              <a-input placeholder="请输入题名" v-decorator="['tiMing']"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6">
            <a-form-item label="文号">
              <a-input placeholder="请输入文号" v-decorator="['wenJianBianHao']"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6">
              <a-form-item label="归档机构">
                <j-select-depart :trigger-change="true" v-decorator="['guiDangJiGou']"></j-select-depart>
              </a-form-item>
            </a-col>
            <a-col :md="6">
              <a-form-item label="保管期限">
                <j-dict-select-tag
                  type="list"
                  v-decorator="['baoGuanQiXian']"
                  dictCode="BaoGuanQiXian"
                  :trigger-change="true"
                  placeholder="请选择保管期限"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6">
              <a-form-item label="密级">
                <j-dict-select-tag
                  type="list"
                  v-decorator="['dangHao']"
                  dictCode="MiJi"
                  :trigger-change="true"
                  placeholder="请选择密级"
                />
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="handleSubmit" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
          <!-- <a-col :sm="24">
            <span style="float: right;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="handleSubmit" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
            </span>
          </a-col>-->
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <a-button @click="handleOk" type="primary">确定</a-button>
      <a-button @click="handleCancel" type="primary">返回</a-button>
    </div>
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="ClearSelected">清空</a>
      </div>
      <a-table
        :columns="columns"
        :data-source="listData"
        bordered
        rowKey="id"
        :loading="loading"
        :pagination="false"
        :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      ></a-table>
    </div>
  </a-card>
</template>

<script>
import { getAction, postAction } from '@/api/manage'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
export default {
  name: 'DaJuanJianNewList',
  components: {
    JDictSelectTag,
    JSelectDepart,
  },
  data() {
    return {
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 80,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '题名',
          align: 'center',
          dataIndex: 'tiMing',
        },
        {
          title: '文号',
          align: 'center',
          dataIndex: 'wenJianBianHao',
        },
        {
          title: '密级',
          align: 'center',
          dataIndex: 'miJi_dictText',
        },
        {
          title: '归档机构',
          align: 'center',
          dataIndex: 'jiGouMingCheng',
        },
        {
          title: '保管期限',
          align: 'center',
          dataIndex: 'baoGuanQiXian_dictText',
        },
        {
          title: '归档年度',
          align: 'center',
          dataIndex: 'nianDu',
        },
      ],
      listData: [],
      selectedRowKeys: [],
      loading: true,
      value: 1,
      id: this.$route.query.id,
      form: this.$form.createForm(this, { name: 'register' }),
      toggleSearchStatus: false,
    }
  },
  created() {
    this.list()
  },
  methods: {
    // 列表
    list() {
      getAction(`/daJuan/wenShuList?id=${this.$route.query.id}`, {}).then((res) => {
        if (res.code == 200) {
          this.listData = res.result.records
          this.loading = false
        }
      })
    },
    // 复选框
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    // 清空
    ClearSelected() {
      this.selectedRowKeys = []
    },
    // 起始序号
    onChangeValue(value) {
      console.log('changed', value)
    },
    // 确定
    handleOk() {
      if (this.selectedRowKeys.length > 0) {
        let ids = this.selectedRowKeys.join()
        let body = {}
        body.ids = ids
        body.id = this.id
        postAction('/daJuan/addJuanNeiWenShu', { ...body }).then((res) => {
          if (res.code == 200) {
            this.$message.success(res.message)
            this.$router.push({ path: '/juanjian', query: { id: this.id } })
          } else {
            this.$message.error(res.message)
          }
        })
      } else {
        this.$message.error('请选择要添加的数据!')
      }
    },
    // 返回
    handleCancel() {
      this.$router.push({ path: '/juanjian', query: { id: this.id } })
    },
    // 查询
    handleSubmit(e) {
      this.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          getAction(`/daJuan/wenShuList?id=${this.$route.query.id}`, { ...values }).then((res) => {
            if (res.code == 200) {
              this.listData = res.result.record
              this.loading = false
            }
          })
        }
      })
    },
    // 重置
    searchReset() {
      this.form.resetFields()
      this.list()
    },
    handleToggleSearch() {
      this.toggleSearchStatus = !this.toggleSearchStatus
    },
  },
}
</script>

<style lang="less" scoped>
.search {
  margin-bottom: 54px;
}

.fold {
  width: calc(100% - 216px);
  display: inline-block;
}

.operator {
  margin-bottom: 18px;
}

@media screen and (max-width: 900px) {
  .fold {
    width: 100%;
  }
}
</style>